<template>
	<view class="content">
		<view class="main">
			<view class="loginText">
				<view>您好,</view>
				<view style="margin-top: 50upx;">欢迎使用守富神</view>
			</view>
			<view class="loginMain">
				<view style="margin-top: 100upx; width: 100%;">
					<input class="loginBtn" type="text" v-model="account" placeholder="请输入企业内部账号" placeholder-class="phcolor" />
				</view>
				<view style="margin-top: 100upx; width: 100%;">
					<input class="loginBtn" type="password" v-model="password" placeholder="请输入密码" placeholder-class="phcolor" />
				</view>
			</view>
			<view class="logins"><button class="login" @tap="login">登录</button></view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
import { _login, _getOpenId, _getUserInfo, _getToken } from '../../common/getToken.js';
export default {
	data() {
		return {
			account: '',
			password: ''
		};
	},
	onLoad() {

		uni.hideHomeButton();
		if (!this.vuex_openId) {
			console.log("拿到数据")
			_getOpenId(this)
		}
		if(this.vuex_account){
			_getToken(this);
		}
	},
	methods: {
		async login() {
			if (this.account == '') {
				uni.showToast({
					title: '请输入账号',
					icon: 'none'
				});
			} else if (this.password == '') {
				uni.showToast({
					title: '请输入密码',
					icon: 'none'
				});
			} else {
				console.log('执行this.vuex_openId=>', this.vuex_openId);

				if (this.vuex_openId) {
					console.log('执行this.vuex_openId=>', this.vuex_openId);
					const state = await _login(this, this.account, this.password);
					console.log('登录状态-===>', state);
					if (state) {
						console.log('跳转');
						await _getUserInfo(this, this.account, this.password);
					}
				} else {
					console.log('没有openid是否执行===>');
					const flag = await _getOpenId(this);
					if (flag == -1) {
						const state = await _login(this, this.account, this.password);
						if (state) {
							await _getUserInfo(this, this.account, this.password);
						}
					}
				}
			}
		}
	},
	mounted() {}
};
</script>

<style>
::-webkit-input-placeholder {
	color: #000000;
}
::-moz-placeholder {
	color: #000000;
}
:-ms-input-placeholder {
	color: #000000;
}
input {
	color: #000000;
}
page {
	background: url(https://cdn.zhikongtianxia.net/godofwealth/businessDistric/login2.png) no-repeat center center;
	background-size: 100% 100%;
}

.content {
	position: relative;
}

.main {
	width: 100%;
	position: absolute;
	top: 30%;
	left: 50%;
	transform: translate(-50%, 30%);
}

.loginText {
	font-size: 60upx;
	color: #fff;
	margin: 0 auto;
	width: 80%;
	/* background: pink; */
	/* width: 80%; */
}

.loginMain {
	width: 80%;
	margin: 0 auto;
}

.loginBtn {
	width: 96%;
	padding: 0 2%;
	height: 90upx;
	background: rgba(255, 255, 255, 0.5);
	color: #1d1b1b;
	margin-top: 50upx;
	border-radius: 15upx;
	font-size: 34upx;
}
.logins {
	display: flex;
	justify-content: center;
}
.login {
	margin-top: 100upx;
	height: 90rpx;
	width: 80%;
	text-align: center;
	line-height: 90rpx;
	background: rgba(97, 160, 60, 1);
	border-radius: 44upx;
	color: #fff;
}

.phcolor {
	color: #fff;
}
</style>
